import 'package:get/get.dart';
import 'package:xindong/common/xindong_api_path.dart';
import 'package:xindong/manager/network/xindong_networking.dart';
import 'package:xindong/res/assets_res.dart';

enum XinDongMessageType {
  system,
  kefu,
  visit,
  help,
}

class XinDongMessageTypeClass {
  XinDongMessageType type;
  String name;
  String? iconName;
  int? count;

  XinDongMessageTypeClass({required this.type, required this.name, this.iconName, this.count = 0});
}

class XinDongNoticeCtr extends GetxController {
  static XinDongNoticeCtr get to => Get.find();

  // 服务列表
  List<XinDongMessageTypeClass> modelList = [];
  int systemCount = 0;
  int kefuCount = 0;

  @override
  void onInit() {
    super.onInit();
    updateList();
  }

  void updateList() {
    modelList.clear();
    modelList = [
      XinDongMessageTypeClass(
        type: XinDongMessageType.system,
        iconName: AssetsRes.MESSAGE_SYSTEM,
        name: "系统通知",
        count: systemCount,
      ),
      XinDongMessageTypeClass(
        type: XinDongMessageType.help,
        iconName: AssetsRes.MESSAGE_HELP,
        name: "帮助中心",
      ),
      XinDongMessageTypeClass(
        type: XinDongMessageType.kefu,
        iconName: AssetsRes.MESSAGE_KEFU,
        name: "官方客服",
        count: kefuCount,
      ),
      XinDongMessageTypeClass(
        type: XinDongMessageType.visit,
        iconName: AssetsRes.MESSAGE_VISIT,
        name: "谁看过我",
        count: 0,
      ),
    ];
    update();
  }

  Future<void> messageUnreadCount() async {
    final object = await XinDongNetworking.instance.request(XinDongApi.messageCount, method: XinDongHttpMethod.post);
    if (object.code == XinDongServerStatus.success) {
      systemCount = object.data;
      updateList();
    }
  }
}
